
import Mock from 'mockjs'

Mock.mock("/api/registers", {

})
Mock.mock("/api/registers", {

})
Mock.mock("/api/registers", {

})


Mock.mock("/api/registers", "post", function (req) {
    var { phone, pass } = JSON.parse(req.body);
    var users = [
        {
            id: 1,
            phone: "123456789",
            pass: "123456"

        },
        {
            id: 2,
            phone: "741852963",
            pass: "123456"

        }
    ];
    var res = users.some((item, index) => {
        return item.phone === phone && item.pass === pass;
    })
    if (res) {
        return { code: 200, msg: "登录成功" };
    }
    else {
        return { code: 400, msg: "登录失败" }
    }
})
Mock.mock("/api/classify", "get", {
    "classify|12": [
        {
            "btn": "@ctitle(3)",
            "con|15": [
                {
                    "id": "@id",
                    "icon": "@image(30x30,@color)",
                    "name": "@ctitle(3)"
                }
            ]
        }
    ]
})

Mock.mock("/api/bottom", "get", {
    "list": [
        {
            "link": "/astore",
            "icon": "icon-shouye_huaban",
            "text": "店铺",
            "id": "0"
        }, {
            "link": "/alassify",
            "icon": "icon-shouye_huaban",
            "text": "分类",
            "id": "1"
        }, {
            "link": "/aomplete",
            "icon": "icon-shouye_huaban",
            "text": "全部",
            "index": "2"
        }, {
            "link": "/ahopping",
            "icon": "icon-shouye_huaban",
            "text": "购物车",
            "id": "3"
        }, {
            "link": "/aersonage",
            "icon": "icon-shouye_huaban",
            "text": "个人",
            "id": "4"
        }
    ]
})
var data = Mock.mock({
    "list|12": [
        {
            "id": "@id",
            "name": "@ctitle(3,6)",
            "icon": "@image(30x30,@color)",
            "price|100-1000": 1,
            "saled|1000-10000": 1
        }

    ]
})

Mock.mock("/api/list", "get", function () {
    return data
})
Mock.mock("/api/aarticulars", "post", function (options) {
    var { id } = JSON.parse(options.body);
    var res = data.list.filter((item) => {
        return item.id == id;
    })
    if (res.length > 0) {
        return res[0]
    }
})
Mock.mock("/api/swiper","get",{
    "list|5":[
      {
        "id":"@id",
        "icon":"@image(400x200,@color)",
        "link":"@url"
      }
    ]
  })